#include <limits.h>
#include <math.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

int* platesBetweenCandles(char* s, int** queries, int queriesSize, int* queriesColSize, int* returnSize);

int main()
{
	return 0;
}

/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
int* platesBetweenCandles(char* s, int** queries, int queriesSize, int* queriesColSize, int* returnSize)
{
	int cnt = 0, len = 0;
	for (int i = 0; s[i]; i++, len++)
		if (s[i] == '*') cnt++;

	int length = len;
	for (int i = len - 1; i >= 0; i--)
		if (s[i] == '*') len--, cnt--;
		else break;

	int* aux = calloc(length, sizeof(int));
	for (int i = len; i < length; i++)
		aux[i] = cnt;
	for (int i = len - 1, pre; i >= 0; i--) {
		if (s[i] == '|') pre = cnt;
		else cnt--;
		aux[i] = pre;
	}

	for (int i = 0; i < length; i++)
		printf("%d\t", aux[i]);

	int* aux_af = calloc(length, sizeof(int));
	for (int i = 0, cnt = 0, pre = 0; i < length; i++) {
		if (s[i] == '*') cnt++;
		else pre = cnt;
		aux_af[i] = pre;
	}

	for (int i = 0; i < length; i++)
		printf("%d\t", aux_af[i]);

	int* res = calloc(queriesSize, sizeof(int));
	for (int i = 0; i < queriesSize; i++) {
		int start = queries[i][0], end = queries[i][1];
		res[i] = fmax(aux_af[end] - aux[start], 0);
	}

	*returnSize = queriesSize;
	return res;
}
